Skip to main content
Glama
bsreeram08

Git Repo Browser MCP

git_hooks

Manage Git hooks in repositories to automate tasks like pre-commit checks, post-merge actions, and workflow enforcement.

Instructions

Manage git hooks in the repository.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
repo_pathYesThe path to the local Git repository
actionYesHook action (list, get, create, enable, disable)list
hook_nameNoName of the hook (e.g., 'pre-commit', 'post-merge')
scriptNoScript content for the hook (for create action)

Implementation Reference

  • Core handler function implementing git_hooks tool logic for listing, getting, and creating Git hooks in a repository.
    export async function handleGitHooks({
      repo_path,
      action,
      hook_name = "",
      script = "",
    }) {
      try {
        // Path to the hooks directory
        const hooksDir = path.join(repo_path, ".git", "hooks");
    
        switch (action) {
          case "list":
            // Get all available hooks
            const files = await fs.readdir(hooksDir);
            const hooks = [];
    
            for (const file of files) {
              // Filter out sample hooks
              if (!file.endsWith(".sample")) {
                const hookPath = path.join(hooksDir, file);
                const stats = await fs.stat(hookPath);
    
                hooks.push({
                  name: file,
                  path: hookPath,
                  size: stats.size,
                  executable: (stats.mode & 0o111) !== 0, // Check if executable
                });
              }
            }
    
            return {
              content: [
                {
                  type: "text",
                  text: JSON.stringify(
                    {
                      success: true,
                      hooks: hooks,
                    },
                    null,
                    2
                  ),
                },
              ],
            };
    
          case "get":
            if (!hook_name) {
              return {
                content: [
                  {
                    type: "text",
                    text: JSON.stringify(
                      { error: "Hook name is required for get action" },
                      null,
                      2
                    ),
                  },
                ],
                isError: true,
              };
            }
    
            const hookPath = path.join(hooksDir, hook_name);
    
            // Check if hook exists
            if (!(await fs.pathExists(hookPath))) {
              return {
                content: [
                  {
                    type: "text",
                    text: JSON.stringify(
                      { error: `Hook '${hook_name}' does not exist` },
                      null,
                      2
                    ),
                  },
                ],
                isError: true,
              };
            }
    
            // Read hook content
            const hookContent = await fs.readFile(hookPath, "utf8");
            const stats = await fs.stat(hookPath);
    
            return {
              content: [
                {
                  type: "text",
                  text: JSON.stringify(
                    {
                      success: true,
                      name: hook_name,
                      content: hookContent,
                      executable: (stats.mode & 0o111) !== 0,
                    },
                    null,
                    2
                  ),
                },
              ],
            };
    
          case "create":
            if (!hook_name) {
              return {
                content: [
                  {
                    type: "text",
                    text: JSON.stringify(
                      { error: "Hook name is required for create action" },
                      null,
                      2
                    ),
                  },
                ],
                isError: true,
              };
            }
    
            if (!script) {
              return {
                content: [
                  {
                    type: "text",
                    text: JSON.stringify(
                      { error: "Script content is required for create action" },
                      null,
                      2
                    ),
                  },
                ],
                isError: true,
              };
            }
    
            const createHookPath = path.join(hooksDir, hook_name);
    
            // Write hook content
            await fs.writeFile(createHookPath, script);
    
            // Make hook executable
            await fs.chmod(createHookPath, 0o755);
    
            return {
              content: [
                {
                  type: "text",
                  text: JSON.stringify(
                    {
                      success: true,
                      message: `Created hook '${hook_name}'`,
                      name: hook_name,
                      executable: true,
                    },
                    null,
                    2
                  ),
                },
              ],
            };
    
          default:
            return {
              content: [
                {
                  type: "text",
                  text: JSON.stringify(
                    { error: `Unknown hook action: ${action}` },
                    null,
                    2
                  ),
                },
              ],
              isError: true,
            };
        }
      } catch (error) {
        return {
          content: [
            {
              type: "text",
              text: JSON.stringify(
                { error: `Failed to manage hook: ${error.message}` },
                null,
                2
              ),
            },
          ],
          isError: true,
        };
      }
    }
  • JSON schema defining the input parameters and structure for the git_hooks tool.
    {
      name: "git_hooks",
      description: "Manage git hooks in the repository.",
      inputSchema: {
        type: "object",
        properties: {
          repo_path: {
            type: "string",
            description: "The path to the local Git repository",
          },
          action: {
            type: "string",
            description: "Hook action (list, get, create, enable, disable)",
            default: "list",
            enum: ["list", "get", "create", "enable", "disable"],
          },
          hook_name: {
            type: "string",
            description:
              "Name of the hook (e.g., 'pre-commit', 'post-merge')",
          },
          script: {
            type: "string",
            description: "Script content for the hook (for create action)",
          },
        },
        required: ["repo_path", "action"],
      },
    },
  • src/server.js:923-923 (registration)
    Maps the 'git_hooks' tool name to its handler function handleGitHooks in the central handlersMap.
    git_hooks: handleGitHooks,
  • Re-exports the handleGitHooks function from other-operations.js for use in server.js.
    handleGitHooks,
  • src/server.js:34-34 (registration)
    Imports handleGitHooks from handlers/index.js into server.js.
    handleGitHooks,
Behavior2/5

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

No annotations are provided, so the description carries full burden. 'Manage' implies both read and write operations, but it doesn't disclose permissions needed, side effects, error handling, or output format. For a tool with multiple actions (including create/enable/disable), this lack of behavioral detail is a significant gap.

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 a single, efficient sentence with zero waste. It's appropriately sized and front-loaded, making it easy to parse quickly.

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 no annotations, no output schema, and a tool with multiple actions (including mutations like create/enable/disable), the description is incomplete. It doesn't explain what 'manage' entails, return values, or behavioral constraints, leaving the agent under-informed.

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 fully documents all 4 parameters. The description adds no parameter-specific information beyond what's in the schema. Baseline 3 is appropriate when the schema does all the work.

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 'Manage git hooks in the repository' states a general purpose but is vague. It specifies the resource ('git hooks') and implies a verb ('manage'), but doesn't clarify what 'manage' entails or how it differs from sibling tools like git_config or git_commit. It's better than a tautology but lacks specificity.

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?

No guidance on when to use this tool versus alternatives is provided. The description doesn't mention prerequisites, context, or exclusions. With many sibling tools available, this omission leaves the agent without clear direction on tool selection.

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

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/bsreeram08/git-commands-mcp'

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