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}`);
      }
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