Skip to main content
Glama
bsreeram08

Git Repo Browser MCP

git_attributes

Manage Git attributes for files in repositories to control how Git handles specific file patterns, enabling configuration of text conversion, diff behavior, and merge strategies.

Instructions

Manage git attributes for files.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
repo_pathYesThe path to the local Git repository
actionYesAction (get, set, list)list
patternNoFile pattern
attributeNoAttribute to set

Implementation Reference

  • Core implementation of the `handleGitAttributes` function, which handles list, get, and set actions for the .gitattributes file in a Git repository.
    export async function handleGitAttributes({
      repo_path,
      action,
      pattern = "",
      attribute = "",
    }) {
      try {
        const attributesPath = path.join(repo_path, ".gitattributes");
    
        switch (action) {
          case "list":
            // Check if .gitattributes exists
            if (!(await fs.pathExists(attributesPath))) {
              return {
                content: [
                  {
                    type: "text",
                    text: JSON.stringify(
                      {
                        success: true,
                        attributes: [],
                        message: ".gitattributes file does not exist",
                      },
                      null,
                      2
                    ),
                  },
                ],
              };
            }
    
            // Read and parse .gitattributes
            const content = await fs.readFile(attributesPath, "utf8");
            const lines = content
              .split("\n")
              .filter((line) => line.trim() && !line.startsWith("#"));
    
            const attributes = lines.map((line) => {
              const parts = line.trim().split(/\s+/);
              return {
                pattern: parts[0],
                attributes: parts.slice(1),
              };
            });
    
            return {
              content: [
                {
                  type: "text",
                  text: JSON.stringify(
                    {
                      success: true,
                      attributes: attributes,
                    },
                    null,
                    2
                  ),
                },
              ],
            };
    
          case "get":
            if (!pattern) {
              return {
                content: [
                  {
                    type: "text",
                    text: JSON.stringify(
                      { error: "Pattern is required for get action" },
                      null,
                      2
                    ),
                  },
                ],
                isError: true,
              };
            }
    
            // Check if .gitattributes exists
            if (!(await fs.pathExists(attributesPath))) {
              return {
                content: [
                  {
                    type: "text",
                    text: JSON.stringify(
                      {
                        success: true,
                        pattern: pattern,
                        attributes: [],
                        message: ".gitattributes file does not exist",
                      },
                      null,
                      2
                    ),
                  },
                ],
              };
            }
    
            // Read and find pattern
            const getContent = await fs.readFile(attributesPath, "utf8");
            const getLines = getContent.split("\n");
    
            const matchingLines = getLines.filter((line) => {
              const parts = line.trim().split(/\s+/);
              return parts[0] === pattern;
            });
    
            if (matchingLines.length === 0) {
              return {
                content: [
                  {
                    type: "text",
                    text: JSON.stringify(
                      {
                        success: true,
                        pattern: pattern,
                        attributes: [],
                        message: `No attributes found for pattern '${pattern}'`,
                      },
                      null,
                      2
                    ),
                  },
                ],
              };
            }
    
            // Parse attributes
            const patternAttributes = matchingLines
              .map((line) => {
                const parts = line.trim().split(/\s+/);
                return parts.slice(1);
              })
              .flat();
    
            return {
              content: [
                {
                  type: "text",
                  text: JSON.stringify(
                    {
                      success: true,
                      pattern: pattern,
                      attributes: patternAttributes,
                    },
                    null,
                    2
                  ),
                },
              ],
            };
    
          case "set":
            if (!pattern) {
              return {
                content: [
                  {
                    type: "text",
                    text: JSON.stringify(
                      { error: "Pattern is required for set action" },
                      null,
                      2
                    ),
                  },
                ],
                isError: true,
              };
            }
    
            if (!attribute) {
              return {
                content: [
                  {
                    type: "text",
                    text: JSON.stringify(
                      { error: "Attribute is required for set action" },
                      null,
                      2
                    ),
                  },
                ],
                isError: true,
              };
            }
    
            // Check if .gitattributes exists, create if not
            if (!(await fs.pathExists(attributesPath))) {
              await fs.writeFile(attributesPath, "");
            }
    
            // Read current content
            const setContent = await fs.readFile(attributesPath, "utf8");
            const setLines = setContent.split("\n");
    
            // Check if pattern already exists
            const patternIndex = setLines.findIndex((line) => {
              const parts = line.trim().split(/\s+/);
              return parts[0] === pattern;
            });
    
            if (patternIndex !== -1) {
              // Update existing pattern
              const parts = setLines[patternIndex].trim().split(/\s+/);
    
              // Check if attribute already exists
              if (!parts.includes(attribute)) {
                parts.push(attribute);
                setLines[patternIndex] = parts.join(" ");
              }
            } else {
              // Add new pattern
              setLines.push(`${pattern} ${attribute}`);
            }
    
            // Write back to file
            await fs.writeFile(
              attributesPath,
              setLines.filter(Boolean).join("\n") + "\n"
            );
    
            return {
              content: [
                {
                  type: "text",
                  text: JSON.stringify(
                    {
                      success: true,
                      message: `Set attribute '${attribute}' for pattern '${pattern}'`,
                      pattern: pattern,
                      attribute: attribute,
                    },
                    null,
                    2
                  ),
                },
              ],
            };
    
          default:
            return {
              content: [
                {
                  type: "text",
                  text: JSON.stringify(
                    { error: `Unknown attributes action: ${action}` },
                    null,
                    2
                  ),
                },
              ],
              isError: true,
            };
        }
      } catch (error) {
        return {
          content: [
            {
              type: "text",
              text: JSON.stringify(
                { error: `Failed to manage git attributes: ${error.message}` },
                null,
                2
              ),
            },
          ],
          isError: true,
        };
      }
    }
  • Input schema definition for the 'git_attributes' tool, specifying parameters like repo_path, action, pattern, and attribute.
    {
      name: "git_attributes",
      description: "Manage git attributes for files.",
      inputSchema: {
        type: "object",
        properties: {
          repo_path: {
            type: "string",
            description: "The path to the local Git repository",
          },
          action: {
            type: "string",
            description: "Action (get, set, list)",
            default: "list",
            enum: ["get", "set", "list"],
          },
          pattern: {
            type: "string",
            description: "File pattern",
          },
          attribute: {
            type: "string",
            description: "Attribute to set",
          },
        },
        required: ["repo_path", "action"],
      },
    },
  • src/server.js:920-920 (registration)
    Registration of the 'git_attributes' handler in the server's handlersMap, mapping the tool name to its implementation function.
    git_attributes: handleGitAttributes,
  • Import of handleGitAttributes from other-operations.js into the handlers index module.
    import {
      handleGitArchive,
      handleGitAttributes,
  • Re-export of handleGitAttributes from handlers/index.js for centralized access.
    handleGitAttributes,
Behavior2/5

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

With no annotations, the description carries full burden but only states 'manage' without detailing what that entails. It doesn't explain whether operations are read-only or mutating, what permissions are needed, how errors are handled, or what the output looks like, leaving significant behavioral gaps.

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, directly stating the tool's purpose without unnecessary elaboration.

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?

For a tool with 4 parameters, no annotations, and no output schema, the description is incomplete. It lacks details on behavioral traits, output format, and usage context, making it inadequate for an agent to fully understand how to invoke and interpret results.

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 parameters. The description adds no additional meaning beyond implying that attributes are managed for files, which aligns with but doesn't expand upon the schema. Baseline 3 is appropriate as the schema does the heavy lifting.

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

Purpose4/5

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

The description clearly states the verb ('manage') and resource ('git attributes for files'), making the purpose understandable. It distinguishes from siblings like git_config or git_lfs by focusing specifically on attributes, though it doesn't explicitly contrast with them.

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 is provided on when to use this tool versus alternatives. The description doesn't mention prerequisites, context, or exclusions, leaving the agent to infer usage from the action parameter alone.

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