Skip to main content
Glama

git_context

Fetch git repository context to provide branch, commits, and diffstat details, eliminating repetitive requests for basic repo information.

Instructions

Fetches a compact git context bundle so the assistant stops asking for basic repo details.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
repoPathYesAbsolute repo path
maxCommitsNoMax commits (1..50)

Implementation Reference

  • Handler logic for git_context tool: validates input, checks if repo, fetches branch, recent commits, and latest commit diffstat using git commands, formats into markdown payload.
    const args = GitContextSchema.parse(request.params.arguments);
    
    // Quick guardrail: fail nicely if this isn't a repo.
    const isRepo = await execFileAsync("git", [
      "-C",
      args.repoPath,
      "rev-parse",
      "--is-inside-work-tree",
    ])
      .then((r) => r.stdout.trim() === "true")
      .catch(() => false);
    
    if (!isRepo) {
      return {
        content: [
          {
            type: "text",
            text: `Not a git repository: ${args.repoPath}`,
          },
        ],
      };
    }
    
    // Branch
    const branch = await execFileAsync("git", [
      "-C",
      args.repoPath,
      "rev-parse",
      "--abbrev-ref",
      "HEAD",
    ]).then((r) => r.stdout.trim());
    
    // Recent commits
    const commits = await execFileAsync("git", [
      "-C",
      args.repoPath,
      "log",
      "-n",
      String(args.maxCommits),
      "--pretty=format:%h %s",
    ]).then((r) => r.stdout.trim());
    
    // Diffstat vs latest commit (simple, fast)
    const diffstat = await execFileAsync("git", [
      "-C",
      args.repoPath,
      "show",
      "--stat",
      "--oneline",
      "-1",
    ]).then((r) => r.stdout.trim());
    
    const payload = [
      "# Repo Context",
      `- Branch: ${branch}`,
      "",
      "## Recent commits",
      commits ? commits.split("\n").map((l) => `- ${l}`).join("\n") : "- None",
      "",
      "## Latest commit diffstat",
      "```",
      diffstat,
      "```",
    ].join("\n");
    
    return {
      content: [{ type: "text", text: payload }],
    };
  • Zod schema defining input parameters for git_context: repoPath (required string), maxCommits (optional number, default 15).
    const GitContextSchema = z.object({
      repoPath: z.string().min(1).describe("Absolute path to a git repository"),
      maxCommits: z.number().int().min(1).max(50).default(15),
    });
  • src/index.ts:100-122 (registration)
    Registers the git_context tool in the ListToolsRequestSchema handler, providing name, description, and inputSchema matching the Zod schema.
    server.setRequestHandler(ListToolsRequestSchema, async () => {
      return {
        tools: [
          {
            name: "git_context",
            description:
              "Fetches a compact git context bundle so the assistant stops asking for basic repo details.",
            inputSchema: {
              type: "object",
              properties: {
                repoPath: { type: "string", description: "Absolute repo path" },
                maxCommits: {
                  type: "number",
                  description: "Max commits (1..50)",
                  default: 15,
                },
              },
              required: ["repoPath"],
            },
          },
        ],
      };
    });
  • src/index.ts:124-127 (registration)
    Registers the CallToolRequestSchema handler which dispatches to git_context implementation.
    server.setRequestHandler(CallToolRequestSchema, async (request) => {
      if (request.params.name !== "git_context") {
        throw new Error(`Unknown tool: ${request.params.name}`);
      }
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. It mentions fetching a 'compact' bundle but doesn't disclose behavioral traits like what data is included, format, performance, or error handling. This leaves gaps in understanding how the tool behaves beyond the basic action.

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

Conciseness4/5

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

The description is a single, efficient sentence that front-loads the purpose. It could be slightly more structured by separating functional intent from benefits, but it avoids waste and is appropriately sized for the tool's complexity.

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 and no output schema, the description is incomplete. It doesn't explain what the 'compact git context bundle' contains, how it's structured, or what the assistant gains, leaving significant gaps in understanding the tool's output and full utility.

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 the two parameters. The description adds no additional meaning beyond implying the tool uses these to fetch context, which aligns with the schema but doesn't enhance parameter understanding. 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 tool's purpose with a specific verb ('fetches') and resource ('git context bundle'), explaining it provides repository details to reduce redundant queries. It doesn't need sibling differentiation since there are no sibling tools, but it could be more specific about what 'basic repo details' includes.

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 implies usage when the assistant needs repository information, but it lacks explicit guidance on when to use this tool versus alternatives or prerequisites. No sibling tools exist, so no comparison is needed, but general context for invocation is missing.

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/sanjaynela/mcpHouseRules'

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