Skip to main content
Glama

git_context

Fetch compact git context bundles to provide repository details, eliminating repetitive requests for basic repo information and streamlining development workflows.

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

  • The handler function for the 'git_context' tool within the CallToolRequestSchema handler. It validates input, checks if the path is a git repo, fetches current branch, recent commits, and diffstat of the latest commit, then formats and returns the git context as text.
    if (request.params.name !== "git_context") { throw new Error(`Unknown tool: ${request.params.name}`); } 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 the input parameters for the git_context tool: required repoPath (string) and optional maxCommits (number, default 15). Used for validation in the handler.
    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:97-119 (registration)
    Registration of the git_context tool in the ListToolsRequestSchema handler, providing the tool's name, description, and input schema for discovery by clients.
    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"], }, }, ], }; });
  • Comment describing the purpose of the git_context tool.
    // 3) Tool: git_context - fetches compact git context 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), });

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